package com.yangrui.app.mapper;

import com.yangrui.app.entity.Video;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VideoMapper {
    /**
     *  根据主建查询
     * @param id id
     * @return video
     */
    @Select("select id,title,summary,cover_img,price,point,create_time from lesson.video where id=#{param1}")
    Video selectById(Integer id);

    /**
     * 全查
     * @return video集合
     */
    @Select("select id,title,summary,cover_img,price,point,create_time from lesson.video")
    List<Video> list();

    @Select("select id , id as video_id, title, summary, cover_img, price, point, create_time from lesson.video where id=#{param1}")
    @Results({
            @Result(id = true ,  property = "id", column = "id" , jdbcType = JdbcType.INTEGER),
            @Result(property = "chapters", column = "video_id", jdbcType = JdbcType.INTEGER,
                    many = @Many(select = "com.yangrui.app.mapper.ChapterMapper.selectByVideoId"))
    })
    Video selectDetailById(Integer id);
}
